#!/usr/bin/env python3.10
# -*- encoding: utf-8 -*-
'''
@File    :   comments.py
@Time    :   2023/05/08 11:22:55
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib
from typing import List,Optional

from fastapi import Query
from pydantic import BaseModel, Field, EmailStr

from .base import BaseFilter, ORMModel

__all__ = ['CommentCreate','CommentUpdate','CommentCreateAdmin','CommentsListOutItemPost','CommentOut','CommentsListOut','CommentFilter']

    
class CommentCreate(BaseModel):
    post_id: int
    body: str
    author: str = Field(..., max_length=30)
    email: EmailStr = Field(...)
    from_admin: bool = False
    is_reviewed: bool = False
    parent_id: int = 0
    replied_id: Optional[int] = None
    
class CommentUpdate(CommentCreate):
    pass


class CommentCreateAdmin(BaseModel):
    post_id: int
    body: str
    from_admin: bool = True
    is_reviewed: bool = True    
    
    
class CommentsListOutItemPost(ORMModel):
    id: int = Field(..., alias='postId', description='文章ID')
    title: str = Field(..., alias='postTitle', description='文章标题')
    
        
class CommentOut(ORMModel):
    """ 评论基本信息 """
    id: int = Field(..., alias='commentId', description='评论ID')
    author: str = Field(..., alias='commentAuthor', description='评论者')
    email: str = Field(..., alias='commentEmail', description='评论者邮箱')
    body: str = Field(..., alias='commentBody', description="评论内容")
    parent_id: int = Field(..., alias='commentParent', description="评论父id")
    
class CommentsListOut(BaseModel):
    total: int
    items: List[CommentOut]
    
      
class CommentFilter(BaseFilter):
    """ 过滤评论 """
    body__icontains: Optional[str] = Query(None, alias="body", description="评论内容模糊查询")
